package com.briup.estore.listener;

import com.briup.estore.entity.ShopEntity;
import com.briup.estore.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import java.util.List;

/**
 * @author adam
 * @date 2023/3/31
 * session对象的声明周期监听
 * 在session创建的时候查询商品信息
 */

public class SessionListener implements HttpSessionListener {
    @Autowired
    private ShopService shopService;

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        List<ShopEntity> disCountList = shopService.findStatusAndDisCount(true);
        List<ShopEntity> shopList = shopService.findStatusAndDisCount(false);
        //获取session对象
        HttpSession session = se.getSession();
        session.setAttribute("disCountList", disCountList);
        session.setAttribute("shopList", shopList);
    }
}
